//
//  ZGLLotteryRecorderCell.m
//  ZeegingLottery
//
//  Created by 李曌 on 2018/6/29.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "ZGLLotteryRecorderCell.h"

@interface ZGLLotteryRecorderCell ()

@property (strong, nonatomic)UILabel *timeLabel;         //时间
@property (strong, nonatomic)UILabel *LotteryTypeLabel;  //彩种名
@property (strong, nonatomic)UILabel *OrderPriceLabel;   //订单金额
@property (strong, nonatomic)UILabel *OrderStatusLable;  //订单状态
@property (strong, nonatomic)UIImageView *accessoryImage;  //箭头



@end



@implementation ZGLLotteryRecorderCell

+ (instancetype)LotteryRecorderCellWith:(UITableView *)tableView
{
    static NSString *cellID = @"LotteryRecorderCell";
    ZGLLotteryRecorderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[ZGLLotteryRecorderCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        
    }
    
    return cell;
}

- (void)setModel:(ZGLOrderModel *)model
{
    if (model) {
        _model = model;
        
        NSString *date = model.create_date;
        NSString *time = model.create_time;
        NSString *aftertaxprize = model.aftertaxprize;
        self.timeLabel.text = [NSString stringWithFormat:@"%@ \n%@",date,time];
        
        self.OrderPriceLabel.text = model.amount;
        
        switch ([model.status integerValue]) {
            case 1:
                _OrderStatusLable.text = @"待支付";
                _OrderStatusLable.textColor = RGBACOLOR(135, 135, 135, 1.0);
                break;
            case 2:
                _OrderStatusLable.text = @"支付中";
                _OrderStatusLable.textColor = RGBACOLOR(135, 135, 135, 1.0);
                break;
            case 3:
                _OrderStatusLable.text = @"待出票";
                _OrderStatusLable.textColor = RGBACOLOR(135, 135, 135, 1.0);
                break;
            case 4:
                _OrderStatusLable.text = @"待开奖";
                _OrderStatusLable.textColor = RGBACOLOR(42, 130, 255, 1.0);
                break;
//            case 5:
//                self.OrderStatusLable.text = @"待派奖";
//                self.OrderStatusLable.textColor = RGBACOLOR(189, 0, 6, 1.0);
//                break;
//            case 6:
//                self.OrderStatusLable.text = @"已派奖";
//                self.OrderStatusLable.textColor = RGBACOLOR(189, 0, 6, 1.0);
//                break;
            case 5:
            case 6:
                _OrderStatusLable.text = [NSString stringWithFormat:@"中奖%@元",aftertaxprize];
                _OrderStatusLable.textColor = RGBACOLOR(189, 0, 6, 1.0);
                break;
            case 7:
                _OrderStatusLable.text = @"未中奖";
                _OrderStatusLable.textColor = RGBACOLOR(135, 135, 135, 1.0);
                break;
            case 8:
                _OrderStatusLable.text = @"已撤单";
                _OrderStatusLable.textColor = RGBACOLOR(135, 135, 135, 1.0);
                break;
            case 9:
                _OrderStatusLable.text = @"已过期";
                _OrderStatusLable.textColor = RGBACOLOR(135, 135, 135, 1.0);
                break;
            case 10:
                _OrderStatusLable.text = @"状态异常";
                _OrderStatusLable.textColor = globalRed;
                break;
                
            default:
                break;
        }
        
    }
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self.contentView addSubview:self.timeLabel];
        [self.contentView addSubview:self.LotteryTypeLabel];
        [self.contentView addSubview:self.OrderPriceLabel];
        [self.contentView addSubview:self.OrderStatusLable];
        [self.contentView addSubview:self.accessoryImage];
        
        [self setupContentUI];
    }
    return self;
}

- (void)setupContentUI
{
    [_accessoryImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self.contentView).offset(-20);
        make.height.equalTo(@(22));
        make.width.equalTo(@(14));
        make.centerY.equalTo(self.contentView);
        
    }];
    
    [_OrderStatusLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(_accessoryImage.mas_left).offset(-10);
        make.centerY.equalTo(_accessoryImage);
        
    }];
    
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(20);
        make.top.equalTo(self.contentView).offset(10);
        make.bottom.equalTo(self.contentView).offset(-10);
        
    }];
    
    [_LotteryTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_timeLabel.mas_right).offset(20);
        make.top.equalTo(self.contentView).offset(10);
    }];
    
    [_OrderPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_LotteryTypeLabel);
        make.bottom.equalTo(self.contentView).offset(-10);
        
    }];
    
}
#pragma mark - getter

- (UILabel *)timeLabel
{
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.textColor = detailTextColor;
        _timeLabel.font = [UIFont systemFontOfSize:13];
        _timeLabel.textAlignment = 0;
        _timeLabel.numberOfLines = 0;
        
        _timeLabel.text = @"6-29 \n17:30";
    }
    
    return _timeLabel;
}

- (UILabel *)LotteryTypeLabel
{
    if (!_LotteryTypeLabel) {
        _LotteryTypeLabel = [[UILabel alloc]init];
        _LotteryTypeLabel.textColor = mainTextColor;
        _LotteryTypeLabel.font = [UIFont systemFontOfSize:14];
        _LotteryTypeLabel.textAlignment = 1;
        
        _LotteryTypeLabel.text = @"竞彩足球";
    }
    return _LotteryTypeLabel;
}

- (UILabel *)OrderPriceLabel
{
    if (!_OrderPriceLabel) {
        _OrderPriceLabel = [[UILabel alloc]init];
        _OrderPriceLabel.textColor = detailTextColor;
        _OrderPriceLabel.font = [UIFont systemFontOfSize:13];
        _OrderPriceLabel.textAlignment = 1;
        
        _OrderPriceLabel.text = @"123.00元";
        
    }
    return _OrderPriceLabel;
}

- (UILabel *)OrderStatusLable
{
    if (!_OrderStatusLable) {
        _OrderStatusLable = [[UILabel alloc]init];
//        _OrderStatusLable.textColor =
        _OrderStatusLable.textAlignment = 1;
        _OrderStatusLable.font = [UIFont systemFontOfSize:14];
        
//        _OrderStatusLable.text = @"待开奖";
    }
    return _OrderStatusLable;
}

- (UIImageView *)accessoryImage
{
    if (!_accessoryImage) {
        _accessoryImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"img_cell_accessory_arrow"]];
    }
    return _accessoryImage;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
